
import org.security.Role
import org.security.User
class CheckboxTagLib {
	def checkedRoles = { attrs, body ->
		
		Integer langId= attrs.languageId?.toInteger();
		Integer userId = attrs.userId?.toInteger();
		String name= attrs.name;
		String value = attrs.value?.toString()
		
		def user = User.get(userId);
		def selectedRoles = user.getAuthorities();
		
		List list= new ArrayList();
		String[] sarr= null;
		for (Role role: Role.list()) {
			String title= role.roleName;
			sarr=new String[3]
			sarr[0]= role.id
			sarr[1]= title
			sarr[2]=0
			for(Role select:selectedRoles){
				if(select.id == role.id) {
					sarr[2]=1;
				}
			}
			list.add(sarr)
		}
		out << render(template:"/checkboxTag", model:[name:name, list:list, value:value])
	}
}
